import com.google.appengine.api.datastore.Entity
import groovyx.gaelyk.datastore.*
import com.google.appengine.api.datastore.Entity

import com.google.appengine.api.datastore.*
import static com.google.appengine.api.datastore.FetchOptions.Builder.*

//DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

//http://stackoverflow.com/questions/4904292/gaelyk-how-to-perform-datastore-queries-on-collection-attributes
/*def r1 = new Entity("rep", "07")
r1.title = "rep1x"
//b1.key = ['Book', '1234'] as Key 
r1.save()


def i0 = new Entity("img22", "01", r1.key)
i0.name = "img0"
i0.save()

def i1 = new Entity("img22", "02", r1.key)
//author1.books = [b1.key, b2.key]
i1.name = "img1"
i1.save()

def i4 = new Entity("img22", "04")
//author1.books = [b1.key, b2.key]
i4.name = "img4"
i4.save()
*/

Entity e = datastore.get("rep","07")
println " r1e key " + e.key + "<br>"

//Query imgQuery = new Query("img22")
//.setAncestor(r1.key);

//def results = datastore.prepare(imgQuery)
//.asList(FetchOptions.Builder.withDefaults());

def query = new Query("img22").setAncestor(e.key)
PreparedQuery pq = datastore.prepare(query)
def entities = pq.asList(withDefaults())//withLimit(10)) 

//results = datastore.getProperties()


//println "list size "  + results.size() + "<br>"

//println results + "<br><br>"
entities.each {
	println "namet is " + it.name  + "<br>"
	println "key  is " + it.key + "<br>" + " parent " + it.parent + "<br><br>"
}




//def y = datastore.get(b1.key)
//println  " y is " + y.title